Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New pipe method for more intuitive multidimensional dim transforms #3790

Merged
merged 1 commit into from
Jan 6, 2020

Conversation

poplarShift
Copy link
Collaborator

@poplarShift poplarShift commented Jun 22, 2019

As discussed in #3636, I propose a thin wrapper around the already present capability of dim transforms to handle custom functions with multiple input dimensions.

I used pipe as name for the new class method, inspired by https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.pipe.html

The following is now possible (example a bit convoluted for the sake of demonstration):

import numpy as np
import pandas as pd
import holoviews as hv
from holoviews import dim

df = pd.DataFrame(np.random.rand(10, 3), columns=['x', 'y', 'z']).cumsum()
e = hv.Scatter(df, 'x', ['y', 'z'])

def func(x, y, z, u, v=None):
    return u+z*np.polyfit(x, y, 1)[1]

dim.pipe(func, 'x', 'y', 10, np.random.rand(10)).max().apply(e)

Edit: Although I start wondering whether it wouldn't be more general to allow passing str arguments instead of transforming them into dims by default. Perhaps a keyword dim_as_str=True could help?

@poplarShift poplarShift added the type: enhancement Minor feature or improvement to an existing feature label Jun 22, 2019
@philippjfr
Copy link
Member

Sorry this has sat for so long. I like the functionality so I'll merge.

@philippjfr philippjfr merged commit e70d701 into master Jan 6, 2020
@philippjfr philippjfr deleted the multidim-transforms branch January 9, 2020 14:48
@poplarShift
Copy link
Collaborator Author

Thanks!

Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants